package com.guiwu.jjj.leecode.easy;

import java.util.Stack;

/**
 * 用两个栈结构实现队列操作，队列为空返回-1
 *
 * @author jiangjinjian
 * @date 2023/2/9
 * @description
 */
public class CQueue {
    //队头栈
    Stack<Integer> queueHeadStack;
    //队尾栈
    Stack<Integer> queueTailStack;

    public CQueue() {
        queueHeadStack = new Stack<Integer>();
        queueTailStack = new Stack<Integer>();
    }

    /**
     * 入队
     *
     * @param value
     */
    public void appendTail(int value) {
        queueTailStack.push(value);
    }


    /**
     * 出队
     *
     * @return
     */
    public int deleteHead() {
        if (queueTailStack.empty() && queueHeadStack.empty()) return -1;
        if(queueHeadStack.empty() && !queueTailStack.empty()){
            while (!queueTailStack.empty())
                queueHeadStack.push(queueTailStack.pop());
        }
        return queueHeadStack.pop();
    }
}
